//
//  SSIncomeOrderViewController.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/10/19.
//

import UIKit


class SSIncomeOrderViewController: UIViewController {
    
    @IBOutlet weak var tableView: UITableView!
        
    var startTime = ""
    var endTime = ""
    var items = [SSEmployeeOrder]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "全部订单工资"
        tableView.backgroundColor = UIColor.themeBlueColor
        view.backgroundColor = UIColor.themeBlueColor
        tableView.register(UINib(nibName: "SSIncomeOrderCell", bundle: Bundle.init(for: SSIncomeOrderCell.self)), forCellReuseIdentifier: "SSIncomeOrderCell")
//        tableView.backgroundColor = UIColor(hex: "DFEFFE")
        tableView.delegate = self
        tableView.dataSource = self
        tableView.separatorStyle = .none
        getBannerNetwork()
        
        self.tableView.es.addPullToRefresh {
            [unowned self] in
            self.tableView.es.stopPullToRefresh()
            getBannerNetwork()
            print("1233")
        }
    }
    
    //banner
    func getBannerNetwork() {
        let param = [
            "pageCurrent": "1",
            "pageSize": "100",
            "phoneNo": kUserPhone,
            "beginTime": startTime,
            "endTime": endTime,
        ] as [String:AnyObject]
        
        
        SSProgressHUD.share.show()
        HttpConnectTools.share.request(urlString: APIUrl.share.getOrderIncome_URL, parameters: param) { (result, error) in
            if let _ = result{
                SSProgressHUD.share.dismiss()
                
                guard let banners = [SSEmployeeOrder].deserialize(from: result, designatedPath:"data.listIncome") else {
                    return
                }
                self.items = banners as! [SSEmployeeOrder]
                self.tableView.reloadData()
            }else{
            }
        }
    }
}

extension SSIncomeOrderViewController: UITableViewDelegate, UITableViewDataSource
{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let vc = SSOrderDetailController()
        vc.orderNo = self.items[indexPath.row].orderNo
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 143
    }
  
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SSIncomeOrderCell") as! SSIncomeOrderCell
        cell.model = items[indexPath.row]
        return cell
    }
    
   
}
